package main

import (
	"fmt"
	"go.uber.org/zap"
)

func main() {
	logger, _ := NewLogger()
	//logger, _ := zap.NewProduction() //生产环境
	//logger, _ := zap.NewDevelopment() //开发环境
	defer logger.Sync() //刷新缓存
	url := "https://www.baidu.com"
	fmt.Println()
	// sugarlogger
	//sugar := logger.Sugar()
	//sugar.Infow("failed to fetch URL",
	//	"url", url,
	//	"attpent", 3,
	//)
	//sugar.Infof("Failed to fetch URL %s", url)

	// logger
	logger.Info("输出错误", zap.String("url", url))
}

func NewLogger() (*zap.Logger, error) {
	cfg := zap.NewProductionConfig()
	cfg.OutputPaths = []string{
		//"./myproject.log",
		"stderr",
	}
	return cfg.Build()
}
